// Copyright 2022 Huawei Cloud Computing Technology Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef CLOUDAPPENGINE_CAEAESUTILS_H
#define CLOUDAPPENGINE_CAEAESUTILS_H


#include <string>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>

#include "CaeLogConfig.h"
#include "../libs/openssl/include/openssl/aes.h"
#include "../libs/openssl/include/openssl/evp.h"

constexpr int KEY_AES_256 = 1;
constexpr int KEY_AES_128 = 0;

constexpr int CAE_AES128_KEY_LEN = 16;
constexpr int CAE_AES256_KEY_LEN = 32;

typedef struct AesInfo {
    int keyType;
    int tagLen;
    std::string strKey;
    std::string strIv;
} AesInfo;

std::vector<uint8_t> HexToBytes(const std::string &hex);

bool ValidAesInfo(const AesInfo *aesInfo);

bool CaeAesGcmDecrypt(std::string &encryptDataHex, const AesInfo *aesInfo, std::string &outData);


#endif // CLOUDAPPENGINE_CAEAESUTILS_H
